<?php

namespace addons\csmitsm\controller;

use addons\csmitsm\library\xcore\xcore\utils\DevXcFaUtils;
use addons\csmitsm\library\xcore\xcflow\utils\DevXcformFieldsUtils;
use addons\csmitsm\library\xcore\xcore\base\XcAToolsAddonsController;

/**
 * 此页面为辅助类
 * http://fastadmin_addons_csmitsm.fa.net/addons/csmitsm/xc_tools/index
 */
class XcTools extends XcAToolsAddonsController
{

    /**
     * http://fastadmin_addons_csmitsm.fa.net/addons/csmitsm/xc_tools/xcflow_add_mdm_table
     */
    public function xcflow_add_mdm_table()
    {
        DevXcformFieldsUtils::insertSystemTableToMdm([
            ["fa_admin", "nickname"],
            ["fa_auth_group", "name"],
            ["csmitsm_xcflow_instance", "flowtitle"],
            ["csmitsm_xcflow_instancetrace", "title"],
            ["csmitsm_xcflow_rystatus", "fstatusname"]
        ]);
    }

    /**
     * http://fastadmin_addons_csmitsm.fa.net/addons/csmitsm/xc_tools/xcflow_replace_dbtable_prefix
     */
    public function xcflow_replace_dbtable_prefix()
    {
        DevXcformFieldsUtils::replaceDbtablePrefix("fa_csmitsm_xcflow", ["publishtablename", "mdmtablename"], []);
        DevXcformFieldsUtils::replaceDbtablePrefix("fa_csmitsm_xcflow_instance_subtable", ["flowsub_tablename"], []);
        DevXcformFieldsUtils::replaceDbtablePrefix("fa_csmitsm_xcflowchartpage", [], ["xcfieldjson"]);
        DevXcformFieldsUtils::replaceDbtablePrefix("fa_csmitsm_xcflowchartpagejson", [], ["fieldjson"]);
        DevXcformFieldsUtils::replaceDbtablePrefix("fa_csmitsm_xcflowdbview", ["viewname"], ["fieldjson"]);
        DevXcformFieldsUtils::replaceDbtablePrefix("fa_csmitsm_xcflowfield", [], ["fieldjson"]);
        DevXcformFieldsUtils::replaceDbtablePrefix("fa_csmitsm_xcflowmdm", [], ["xcfieldjson"]);
        DevXcformFieldsUtils::replaceDbtablePrefix("fa_csmitsm_xcflowmdmfield", [], ["fieldjson"]);
        DevXcformFieldsUtils::replaceDbtablePrefix("fa_csmitsm_xcflowviewpageview", ["tablename"], ["configjson"]);
    }

    /**
     * http://fastadmin_addons_csmitsm.fa.net/addons/csmitsm/xc_tools/fa_generate_install_sql
     */
    public function fa_generate_install_sql()
    {
        DevXcFaUtils::generate_install_sql("
CREATE OR REPLACE VIEW `fa_csmitsm_xcflowallform` AS  SELECT `t1`.`id` AS `xid`,CONCAT(`t1`.`name`,'(流程表)') AS `name`,`t1`.`xcformtype` AS `xcformtype`,`t1`.`id` AS `xcform_id`,`t1`.`publishtablename` AS `tablename`,`t1`.`xcfieldjson` AS `table_xcfieldjson`,`t1`.`displayfieldcode` AS `displayfieldcode`,'' AS `view_fieldjson`,`t1`.`status` AS `status` FROM `fa_csmitsm_xcflow` `t1` UNION ALL SELECT `t1a`.`id` AS `id`,CONCAT(`t1a`.`name`,'(归档表)') AS `CONCAT(``t1a``.``name``, '(归档表)')`,`t1a`.`xcformtype` AS `xcformmdm`,`t1a`.`id` AS `id`,`t1a`.`mdmtablename` AS `mdmtablename`,`t1a`.`xcfieldjson` AS `xcfieldjson`,`t1a`.`displayfieldcode` AS `displayfieldcode`,'' AS `view_fieldjson`,`t1a`.`status` AS `status` FROM `fa_csmitsm_xcflow` `t1a` WHERE (`t1a`.`mdmtabletype` = 'create_table') UNION ALL SELECT `t2`.`id` AS `id`,`t2`.`name` AS `name`,'mdm' AS `mdm`,`t2`.`id` AS `id`,`t2`.`publishtablename` AS `publishtablename`,`t2`.`xcfieldjson` AS `xcfieldjson`,`t2`.`displayfieldcode` AS `displayfieldcode`,'' AS `Name_exp_26`,`t2`.`status` AS `status` FROM `fa_csmitsm_xcflowmdm` `t2` UNION ALL SELECT `t3`.`id` AS `id`,`t3`.`name` AS `name`,'view' AS `view`,`t3`.`id` AS `id`,`t3`.`viewname` AS `viewname`,'' AS `Name_exp_33`,'' AS `Name_exp_34`,`t3`.`fieldjson` AS `fieldjson`,'normal' AS `normal` FROM `fa_csmitsm_xcflowdbview` `t3`;    
CREATE OR REPLACE VIEW `fa_csmitsm_view_flow_wx_gongdan` AS  SELECT  `t`.`id`      AS `id`,  `t`.`user_id`     AS `user_id`,  `t`.`admin_id`     AS `admin_id`,  `t`.`createtime`    AS `createtime`,  `t`.`updatetime`    AS `updatetime`,  `t`.`weigh`     AS `weigh`,  `t`.`status`     AS `status`,  `t`.`no`      AS `no`,  `t`.`name`      AS `name`,  `t`.`device_id`    AS `device_id`,  `t`.`place`     AS `place`,  `t`.`repairrequester`   AS `repairrequester`,  `t`.`repairrequester_mobile` AS `repairrequester_mobile`,  `t`.`occuredatetime`   AS `occuredatetime`,  `t`.`expectfixdatetime`  AS `expectfixdatetime`,  `t`.`bugdesc`     AS `bugdesc`,  `t`.`bugimages`    AS `bugimages`,  `t`.`feeitem_ids`    AS `feeitem_ids`,  `t`.`servicerate`    AS `servicerate`,  `t`.`fixrate`     AS `fixrate`,  `t`.`improvesugguest`   AS `improvesugguest`,  `t`.`chulijieguo_id`   AS `chulijieguo_id`,  `t`.`fixdate`     AS `fixdate`,  `t`.`fixcontent`    AS `fixcontent`,  `t`.`fiximages`    AS `fiximages`,  `t`.`assign_admin_id`   AS `assign_admin_id`,  `a1`.`id`      AS `xcflow_instance_id`,  `a1`.`xcflow_fstatuscode`  AS `xcflow_fstatuscode`,  `a1`.`xcflow_fstatusname`  AS `xcflow_fstatusname`,  `a1`.`xcflow_toaudit_type`  AS `xcflow_toaudit_type`,  `a1`.`xcflow_toaudit_admin_id` AS `xcflow_toaudit_admin_id`,  `a1`.`xcflow_toaudit_role_id` AS `xcflow_toaudit_role_id` FROM (`fa_csmitsm_flow_wx_gongdan` `t`  LEFT JOIN `fa_csmitsm_xcflow_instance` `a1`   ON (((`t`.`id` = `a1`.`xcflow_flowdata_id`)    AND (`a1`.`xcflow_id` = 61))));
CREATE OR REPLACE VIEW `fa_csmitsm_view_flow_gongdan` AS  SELECT  `t`.`id`      AS `id`,  `t`.`user_id`     AS `user_id`,  `t`.`admin_id`     AS `admin_id`,  `t`.`createtime`    AS `createtime`,  `t`.`updatetime`    AS `updatetime`,  `t`.`weigh`     AS `weigh`,  `t`.`status`     AS `status`,  `t`.`title`     AS `title`,  `t`.`youxianji_id`    AS `youxianji_id`,  `t`.`content`     AS `content`,  `t`.`assign_admin_id`   AS `assign_admin_id`,  `t`.`fixdate`     AS `fixdate`,  `t`.`chulijieguo_id`   AS `chulijieguo_id`,  `t`.`fixcontent`    AS `fixcontent`,  `t`.`gongdanleixing_id`  AS `gongdanleixing_id`,  `a1`.`id`      AS `xcflow_instance_id`,  `a1`.`xcflow_fstatuscode`  AS `xcflow_fstatuscode`,  `a1`.`xcflow_fstatusname`  AS `xcflow_fstatusname`,  `a1`.`xcflow_toaudit_type`  AS `xcflow_toaudit_type`,  `a1`.`xcflow_toaudit_admin_id` AS `xcflow_toaudit_admin_id`,  `a1`.`xcflow_toaudit_role_id` AS `xcflow_toaudit_role_id` FROM (`fa_csmitsm_flow_gongdan` `t`  LEFT JOIN `fa_csmitsm_xcflow_instance` `a1`   ON (((`t`.`id` = `a1`.`xcflow_flowdata_id`)    AND (`a1`.`xcflow_id` = 59))));
        ");
    }

    /**
     * http://fastadmin_addons_csmitsm.fa.net/addons/csmitsm/index/fa_add_menu_function
     */
    public function fa_add_menu_function()
    {
        DevXcFaUtils::add_menu_function(109, "xcflow", [
            ["mdmconfig", "配置"],
            ["mdmconfig", "配置"],
            ["selectTables", "选择表格"],
            ["selectTablefields", "选择表字段"],
            ["publishmenu", "发布菜单"],
        ]);
        DevXcFaUtils::add_menu_function(263, "xcflowdbview", [
            ["selectTables", "选择表格"],
            ["selectTablefields", "选择表字段"],
            ["selectTablefields2", "选择表字段2"]
        ]);
        DevXcFaUtils::add_menu_function(208, "xcflowmdm", [
            ["fieldconfig", "选择表格"],
            ["publishmenu", "发布菜单"]
        ]);
        DevXcFaUtils::add_menu_function(220, "xcflowmdmdata", [
            ["createOrUpdateXcformPage", "创建"],
            ["createOrUpdateXcformSaveAjax", "保存"],
            ["createOrUpdateXcformSubmitAjax", "提交"],
            ["showXcformPage", "详情"],
            ["queryRelateSubTableFieldsAndDatasByFieldcode", "查询子表数据"],
            ["getTabledataRowByFieldcodeAndDataid", "查询字段值"],
            ["queryTabledataListByFieldcode", "选择表格数据"],
            ["upload", "上传文件"],
        ]);

        DevXcFaUtils::add_menu_function(251, "xcflowviewpage", [
            ["configpage", "页面配置"],
        ]);

        DevXcFaUtils::add_menu_function(257, "xcflowviewpageview", [
            ["configview", "页面配置"],
            ["addConfigview", "增加页面"],
            ["deleteConfigview", "删除页面"],
            ["savesubmit", "保存"],
            ["queryFieldsByTableName", "查询字段"],
            ["getXcformjsonByTablename", "获取表格配置"],
            ["getTableDatasByTablename", "选择表格数据"],
        ]);

        DevXcFaUtils::add_menu_function(336, "xcflowviewpageviewdata", [
            ["indexajax", "查询数据"],
            ["createOrUpdateXcformPage", "创建"],
            ["showXcformPage", "详情"]
        ]);

        DevXcFaUtils::add_menu_function(337, "xcmyflowinstance", [
            ["createOrUpdateXcformPage", "创建"],
            ["createOrUpdateXcformSaveAjax", "保存"],
            ["createOrUpdateXcformSubmitAjax", "提交"],
            ["showXcformPage", "详情"],
            ["queryRelateSubTableFieldsAndDatasByFieldcode", "查询子表数据"],
            ["getTabledataRowByFieldcodeAndDataid", "查询字段值"],
            ["queryTabledataListByFieldcode", "选择表格数据"],
            ["upload", "上传文件"],
            ["allflows", "创建流程"],
            ["showXcflowPage", "详情"],
            ["showXcformPage", "详情"],
            ["submitPassFlowAjax", "流程审核"],
            ["submitRejectFlowAjax", "流程退回"],
            ["showFlowPageGraph", "流程配置"],
            ["submitPassFlowAjax", "流程审核"],
            ["index", "我的流程"],
            ["index_daiban", "我的待办流程查询"],
            ["index_mycreate", "我的创建流程查询"],
            ["index_myaudit", "我的待审批流程查询"],
        ]);

        DevXcFaUtils::add_menu_function(399, "xcflowchartpage", [
            ["fieldconfig", "页面配置"],
            ["publishmenu", "发布菜单"],
        ]);

        DevXcFaUtils::add_menu_function(412, "xcflowviewpageview_instance", [
            ["detail", "显示页面"],
            ["getXcchartOptions", "获取图表数据"],
        ]);
    }
}
